package znbkTestPaperRdtz.presenter;

import android.util.Log;

import znbkListRdtz.IHeatPointExtensionPresenter;
import com.example.lancooznbk.view.base.ILoadPaperView;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import znbkTestPaperRdtz.ZnbkPaperRdtzInfor;
import znbkTestPaperRdtz.activity.HeatPointExtensionPaperActivity;
import znbkTestPaperRdtz.activity.HeatPointExtensionPaperSplActivity;
import znbkTestPaperRdtz.entity.HeatPointExtensionPaperEntity;
import znbkTestPaperRdtz.api.HeatPointExtensionPaperApi;

/**
 * Created by Administrator on 2018\3\14 0014.
 */

public class HeatPointExtensionPaperPresenter implements IHeatPointExtensionPresenter {

    private ILoadPaperView view;

    public HeatPointExtensionPaperPresenter(ILoadPaperView view) {
        this.view = (ILoadPaperView) view;
    }

    @Override
    public void getData(boolean isShowLoading) {
        if (isShowLoading) view.showLoading();

        HttpOnNextListener<HeatPointExtensionPaperEntity> httpOnNextListener = new HttpOnNextListener<HeatPointExtensionPaperEntity>() {
            @Override
            public void onNext(HeatPointExtensionPaperEntity heatPointExtensionPaperEntity) {


                if (heatPointExtensionPaperEntity.getResFromTK() != null) {
                    view.hideLoading();
                    view.loadPaperData(heatPointExtensionPaperEntity);
                }else {
                    view.showNoData("暂无内容");
                }
            }


            @Override
            public void onError(Throwable e) {
                super.onError(e);
                view.showNetError();
            }

            @Override
            public void onComplete() {
                super.onComplete();
                Log.d("TML","end: "+System.currentTimeMillis());
            }
        };

        HeatPointExtensionPaperApi api = null;
        if(ZnbkPaperRdtzInfor.IsFromSpl){
             api = new HeatPointExtensionPaperApi(httpOnNextListener, (HeatPointExtensionPaperSplActivity) view);
        }else {
             api = new HeatPointExtensionPaperApi(httpOnNextListener, (HeatPointExtensionPaperActivity) view);
        }

        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    @Override
    public void getDataByStatus(int position) {
        getData(false);
    }

    @Override
    public void getDataByQuesType(String quesTypeId) {
        getData(false);
    }

    @Override
    public void getDataByQuesRank(int quesRankId) {

    }


}